<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qquickrectangle.cpp -->
  <title>Gradient QML 类型 | Qt Quick 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtquick-index.html">Qt Quick 模块</a></td><td ><a href="qtquick-qmlmodule.html">QML类型</a></td><td >Gradient QML 类型</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtquick-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">目录</a></h3>
<ul>
<li class="level1"><a href="#properties">属性</a></li>
<li class="level1"><a href="#details">详细信息</a></li>
<li class="level2"><a href="#example-usage">示例用法</a></li>
<li class="level2"><a href="#performance-and-limitations">性能和局限性</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Gradient QML 类型</h1>
<span class="subtitle"></span>
<!-- $$$Gradient-brief -->
<p>Defines a gradient fill. <a href="#details">更多...</a></p>
<!-- @@@Gradient -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> 导入语句：</td><td class="memItemRight bottomAlign"> import QtQuick 2.12</td></tr><tr><td class="memItemLeft rightAlign topAlign"> 被继承：</td><td class="memItemRight bottomAlign"> <p><a href="qml-qtquick-shapes-shapegradient.html">ShapeGradient</a></p>
</td></tr></table></div><ul>
<li><a href="qml-qtquick-gradient-members.html">所有成员的列表，包括继承成员</a></li>
</ul>
<a name="properties"></a>
<h2 id="properties">属性</h2>
<ul>
<li class="fn"><b><b><a href="qml-qtquick-gradient.html#orientation-prop">orientation</a></b></b> : enumeration</li>
<li class="fn"><b><b><a href="qml-qtquick-gradient.html#stops-prop">stops</a></b></b> : list&lt;GradientStop&gt;</li>
</ul>
<!-- $$$Gradient-description -->
<a name="details"></a>
<h2 id="details">详细信息</h2>
<p>A gradient is defined by two or more colors, which will be blended seamlessly.</p>
<p>The colors are specified as a set of <a href="qml-qtquick-gradientstop.html">GradientStop</a> child items, each of which defines a position on the gradient from 0.0 to 1.0 and a color. The position of each <a href="qml-qtquick-gradientstop.html">GradientStop</a> is defined by setting its <a href="qml-qtquick-gradientstop.html#position-prop">position</a> property; its color is defined using its <a href="qml-qtquick-gradientstop.html#color-prop">color</a> property.</p>
<p>A gradient without any gradient stops is rendered as a solid white fill.</p>
<p>Note that this item is not a visual representation of a gradient. To display a gradient, use a visual item (like <a href="qml-qtquick-rectangle.html">Rectangle</a>) which supports the use of gradients.</p>
<a name="example-usage"></a>
<h2 id="example-usage">示例用法</h2>
<div class="float-right"><p><img src="images/qml-gradient.png" alt="" /></p>
</div><p>The following example declares a <a href="qml-qtquick-rectangle.html">Rectangle</a> item with a gradient starting with red, blending to yellow at one third of the height of the rectangle, and ending with green:</p>
<pre class="qml">

  <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> {
      <span class="name">width</span>: <span class="number">100</span>; <span class="name">height</span>: <span class="number">100</span>
      <span class="name">gradient</span>: <span class="name">Gradient</span> {
          <span class="type"><a href="qml-qtquick-gradientstop.html">GradientStop</a></span> { <span class="name">position</span>: <span class="number">0.0</span>; <span class="name">color</span>: <span class="string">&quot;red&quot;</span> }
          <span class="type"><a href="qml-qtquick-gradientstop.html">GradientStop</a></span> { <span class="name">position</span>: <span class="number">0.33</span>; <span class="name">color</span>: <span class="string">&quot;yellow&quot;</span> }
          <span class="type"><a href="qml-qtquick-gradientstop.html">GradientStop</a></span> { <span class="name">position</span>: <span class="number">1.0</span>; <span class="name">color</span>: <span class="string">&quot;green&quot;</span> }
      }
  }

</pre>
<br style="clear: both" /><a name="performance-and-limitations"></a>
<h2 id="performance-and-limitations">性能和局限性</h2>
<p>Calculating gradients can be computationally expensive compared to the use of solid color fills or images. Consider using gradients for static items in a user interface.</p>
<p>Since Qt 5.12, vertical and horizontal linear gradients can be applied to items. If you need to apply angled gradients, a combination of rotation and clipping can be applied to the relevant items. Alternatively, consider using <a href="qtquick-module.html">QtQuick</a>.Shapes::LinearGradient or <a href="../qtgraphicaleffects/qml-qtgraphicaleffects-lineargradient.html">QtGraphicalEffects::LinearGradient</a>. These approaches can all introduce additional performance requirements for your application.</p>
<p>The use of animations involving gradient stops may not give the desired result. An alternative way to animate gradients is to use pre-generated images or SVG drawings containing gradients.</p>
<p><b>请参考 </b><a href="qml-qtquick-gradientstop.html">GradientStop</a>。</p>
<!-- @@@Gradient -->
<h2>属性文档</h2>
<!-- $$$orientation -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="orientation-prop">
<td class="tblQmlPropNode"><p>
<a name="orientation-prop"></a><span class="name">orientation</span> : <span class="type"><a href="../qtqml/qml-enumeration.html">enumeration</a></span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>Set this property to define the direction of the gradient.</p>
<ul>
<li>Gradient.Vertical - a vertical gradient</li>
<li>Gradient.Horizontal - a horizontal gradient</li>
</ul>
<p>The default is Gradient.Vertical.</p>
<p>This property was introduced in  Qt 5.12.</p>
</div></div><!-- @@@orientation -->
<br/>
<!-- $$$stops -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="stops-prop">
<td class="tblQmlPropNode"><p>
<a name="stops-prop"></a><span class="qmldefault">[default] </span><span class="name">stops</span> : <span class="type"><a href="../qtqml/qml-list.html">list</a></span>&lt;<span class="type"><a href="qml-qtquick-gradientstop.html">GradientStop</a></span>&gt;</p></td></tr>
</table></div>
</div><div class="qmldoc"><p>This property holds the gradient stops describing the gradient.</p>
<p>By default, this property contains an empty list.</p>
<p>To set the gradient stops, define them as children of the Gradient.</p>
</div></div><!-- @@@stops -->
<br/>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
